package com.buybuyyi.stylistcrm.order.dao.impl;

import com.buybuyyi.stylistcrm.order.dao.TransferOrderDao;
import com.buybuyyi.stylistcrm.order.helper.OrderGoodsHelper;
import com.buybuyyi.stylistcrm.order.mapper.TransferOrderMapper;
import com.buybuyyi.stylistcrm.order.po.TransferOrder;
import com.buybuyyi.stylistcrm.utils.DateUtil;
import com.buybuyyi.stylistcrm.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import stylistcrm.core.services.order.dto.OrderGoodsDto;
import stylistcrm.core.services.order.dto.PurchaseOrderDto;
import stylistcrm.core.services.order.dto.QueryOrderConditionDto;
import stylistcrm.core.services.order.dto.TransferOrderDto;
import stylistcrm.core.services.order.enums.EnumOrderStatus;
import stylistcrm.core.services.order.enums.EnumOrderType;

import java.util.List;

/**
 * Created by cheny on 2016/9/4.
 */
@Repository
public class TransferOrderDaoImpl implements TransferOrderDao {
    @Autowired
    private TransferOrderMapper transferOrderMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return transferOrderMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(TransferOrder record) {
        return transferOrderMapper.insert(record);
    }

    @Override
    public int insertSelective(TransferOrder record) {
        return transferOrderMapper.insertSelective(record);
    }

    @Override
    public TransferOrder selectByPrimaryKey(Integer id) {
        return transferOrderMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(TransferOrder record) {
        return transferOrderMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(TransferOrder record) {
        return transferOrderMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<TransferOrderDto> getPageList(QueryOrderConditionDto queryCondition) {
        OrderGoodsHelper.setDefaultOrderBy(queryCondition, EnumOrderType.TRANSFER_ORDER);
        List<TransferOrderDto> transferOrderDtoList=transferOrderMapper.getPageList(queryCondition);
        if(null!=transferOrderDtoList&&0!=transferOrderDtoList.size()){
            for(TransferOrderDto transferOrder:transferOrderDtoList){
                List<OrderGoodsDto> orderGoodsDtoList=transferOrder.getGoods();
                OrderGoodsHelper.setGoodsNameAndCount(orderGoodsDtoList,transferOrder);
                if(StringUtil.isNotBlank(transferOrder.getOrderTime())){
                    transferOrder.setOrderTime(DateUtil.formatDatetime(transferOrder.getOrderTime()));
                }
                if(StringUtil.isNotBlank(transferOrder.getOrderStatus())){
                    transferOrder.setOrderStatus(EnumOrderStatus.getEnum(transferOrder.getOrderStatus()).getDesc());
                }

            }
        }
        return transferOrderDtoList;
    }

    @Override
    public List<Integer> getPageIdList(QueryOrderConditionDto queryCondition) {
        return transferOrderMapper.getPageIdList(queryCondition);
    }

    @Override
    public Integer getTotalCount(QueryOrderConditionDto queryCondition) {
        return transferOrderMapper.getTotalCount(queryCondition);
    }
}
